import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { getWeekMonthQuarterYear } from '/@/utils';
import JSwitch from '@/components/Form/src/jeecg/components/JSwitch.vue';
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '登录账号',
    align: 'center',
    dataIndex: 'username',
  },
  {
    title: '真实姓名',
    align: 'center',
    dataIndex: 'realname',
  },
  {
    title: '头像',
    align: 'center',
    dataIndex: 'avatar',
    customRender: render.renderImage,
  },
  {
    title: '生日',
    align: 'center',
    dataIndex: 'birthday',
    customRender: ({ text }) => {
      text = !text ? '' : text.length > 10 ? text.substr(0, 10) : text;
      return text;
    },
  },
  {
    title: '角色',
    align: 'center',
    dataIndex: 'role_dictText',
  },
  {
    title: '性别',
    align: 'center',
    dataIndex: 'sex_dictText',
  },
  {
    title: '电子邮件',
    align: 'center',
    dataIndex: 'email',
  },
  {
    title: '电话',
    align: 'center',
    dataIndex: 'phone',
  },
  {
    title: '状态',
    align: 'center',
    dataIndex: 'status',
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '登录账号',
    field: 'username',
    component: 'Input',
    //colProps: {span: 6},
  },
  {
    label: '真实姓名',
    field: 'realname',
    component: 'Input',
    //colProps: {span: 6},
  },
  {
    label: '角色',
    field: 'role',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'bis_user_role',
    },
    //colProps: {span: 6},
  },
  {
    label: '性别',
    field: 'sex',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'sex',
    },
    //colProps: {span: 6},
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '头像',
    field: 'avatar',
    component: 'JImageUpload',
    componentProps: {
      fileMax: 0,
    },
  },
  {
    label: '登录账号',
    field: 'username',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入登录账号!' }];
    },
  },
  {
    label: '真实姓名',
    field: 'realname',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入真实姓名!' }];
    },
  },

  {
    label: '生日',
    field: 'birthday',
    component: 'DatePicker',
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
    },
  },
  {
    label: '角色',
    field: 'role',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'bis_user_role',
    },
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入角色!' }];
    },
  },
  {
    label: '性别',
    field: 'sex',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'sex',
      stringToNumber: true,
    },
  },
  {
    label: '电子邮件',
    field: 'email',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入电子邮件!' },
        { pattern: /^([\w]+\.*)([\w]+)@[\w]+\.\w{3}(\.\w{2}|)$/, message: '请输入正确的电子邮件!' },
      ];
    },
  },
  {
    label: '电话',
    field: 'phone',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入电话!' },
        { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号码!' },
      ];
    },
  },
  {
    label: '状态',
    field: 'status',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'user_status',
      stringToNumber: true,
    },
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

// 高级查询数据
export const superQuerySchema = {
  username: { title: '登录账号', order: 0, view: 'text', type: 'string' },
  realname: { title: '真实姓名', order: 1, view: 'text', type: 'string' },
  avatar: { title: '头像', order: 2, view: 'image', type: 'string' },
  birthday: { title: '生日', order: 3, view: 'date', type: 'string' },
  role: { title: '角色', order: 4, view: 'list', type: 'string', dictCode: 'bis_user_role' },
  sex: { title: '性别', order: 5, view: 'number', type: 'number', dictCode: 'sex' },
  email: { title: '电子邮件', order: 6, view: 'text', type: 'string' },
  phone: { title: '电话', order: 7, view: 'text', type: 'string' },
  status: { title: '状态', order: 8, view: 'number', type: 'number', dictCode: 'user_status' },
};

/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
